package com.manxi.mapper;

import com.manxi.annotation.AutoFill;
import com.manxi.entity.SetmealDish;
import com.manxi.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    /**
     * 根据菜品id查询套餐
     *
     * @param dishIds
     * @return
     */
    @Select("<script> " +
            "select setmeal_id from setmeal_dish where dish_id in " +
            "<foreach collection='dishIds' item='dishId' separator=',' open='(' close=')'> #{dishId} </foreach> " +
            "</script>"
    )
    List<Long> getSetmealIdsByDishIds(List<Long> dishIds);

    /**
     * 添加套餐菜品表
     * @param setmealDishes
     */
    @Insert("<script> "+
            "insert into setmeal_dish (setmeal_id,dish_id,name,price,copies) values "+
            "<foreach collection='setmealDishes' item='sd' separator=','>" +
            "(#{sd.setmealId},#{sd.dishId},#{sd.name},#{sd.price},#{sd.copies}) "+
            "</foreach> "+
            "</script>")
    @AutoFill(value = OperationType.INSERT)
    void insertBatch(List<SetmealDish> setmealDishes);

    /**
     * 删除套餐和菜品相关信息
     * @param setmealId
     */
    @Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
    void detele(Long setmealId);


    /**
     * 根据套餐id查询套餐菜品表
     * @param id
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> getSetmealDishBySetmealId(Long id);

}
